package chapter19_Enum;

/**
 * Date: 2019/6/18
 * Time: 10:49
 * User: Driss.
 * Description：
 */

//:enumerated/EnumClass.java
// Capabilities of the Enum class

enum Shrubbery {GROUND,CRAWLING,HANGING}

public class EnumClass {
    public static void main(String[] args) {
        for(Shrubbery s : Shrubbery.values()){
            System.out.println(s + " ordinal: " + s.ordinal());
            System.out.println(s.compareTo(Shrubbery.CRAWLING) + " ");
            System.out.println(s.equals(Shrubbery.CRAWLING) + " ");

            System.out.println(s == Shrubbery.CRAWLING);
            System.out.println(s.getDeclaringClass());  ////获得enum实例所属的enum类
            System.out.println(s.name());  //获取enum实例的名字，与使用toString()方法效果相同

            System.out.println("----------------");
        }

        //Produce an enum value from a string name:
        for(String s : "HANGING CRAWLING GROUND".split(" ")){
            Shrubbery shrub = Enum.valueOf(Shrubbery.class, s);  //根据给定的名字返回相应的enum实例，如果不存在给定名字的实例，将会抛出异常
            System.out.println(shrub);
        }

    }
}
